package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.core.domain.AjaxResult;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.Taizhang003;
import com.aidex.biz.service.Taizhang003Service;
import org.springframework.web.multipart.MultipartFile;
import com.aidex.common.utils.SecurityUtils;

/**
 * 警示教育登记台Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/biz/bizTaizhang003")
public class Taizhang003Controller extends BaseController
{
    @Autowired
    private Taizhang003Service taizhang003Service;

    /**
     * 查询警示教育登记台列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:list')")
    @GetMapping("/list")
    public R<PageInfo> list(Taizhang003 taizhang003, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                taizhang003.setCompanyId(null);
        }else{
                     taizhang003.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        taizhang003.setPage(new PageDomain(request, response));
        return R.data(taizhang003Service.findPage(taizhang003));
    }

    /**
     * 获取警示教育登记台详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:query')")
    @GetMapping(value = "/{id}")
    public R<Taizhang003> detail(@PathVariable("id") String id)
    {
        return R.data(taizhang003Service.get(id));
    }

    /**
     * 新增警示教育登记台
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:add')")
    @Log(title = "警示教育登记台", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  Taizhang003 taizhang003)
    {
        return R.status(taizhang003Service.save(taizhang003));
    }

    /**
     * 修改警示教育登记台
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:edit')")
    @Log(title = "警示教育登记台", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated Taizhang003 taizhang003)
    {
        return R.status(taizhang003Service.save(taizhang003));
    }


    /**
     * 删除警示教育登记台
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:remove')")
    @Log(title = "警示教育登记台", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(taizhang003Service.deleteTaizhang003ByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(taizhang003Service.findMaxSort(new Taizhang003()));
    }

    /**
     * 导出警示教育登记台列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhang003:export')")
    @Log(title = "警示教育登记台", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(Taizhang003 taizhang003)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    taizhang003.setCompanyId(null);
            }else{
                         taizhang003.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<Taizhang003> list = taizhang003Service.findList(taizhang003);
        ExcelUtil<Taizhang003> util = new ExcelUtil<Taizhang003>(Taizhang003.class);
        return util.exportExcel(list, "警示教育登记台数据");
    }

        @Log(title = "警示教育登记台导入", businessType = BusinessType.IMPORT)
        @PostMapping("/importData")
        public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
            ExcelUtil<Taizhang003> util = new ExcelUtil<Taizhang003>(Taizhang003.class);
            List<Taizhang003> taizhang003List = util.importExcel(file.getInputStream());
            String message = taizhang003Service.importData(taizhang003List);
            return AjaxResult.success(message);
        }


}
